<?php
namespace Home\Controller;
class IndexController extends HomeController {
    public function index(){
		//首页推荐1 站点top40
		$this ->getArticles();
		$this ->meta_title = C('WEB_SITE_KEYWORD')? C('WEB_SITE_KEYWORD'):'友品集招商网站';
        $this->display('Index/zs_index');
    }
	
	public function need() {
		$this ->meta_title = '国民需求';
		$this->display('Index/need_index');
	}
	
	public function about() {
		$this ->meta_title = '关于我们';
		$this->display('Index/about_index');
	}
	
	public function policy() {
		$this ->meta_title = '品牌优势';
		$this->display('Index/policy_index');
	}
	
	public function answer() {
		$this ->meta_title = '合作问答';
		$interlocution = M('interlocution')->select();
		$this->assign('interlocution', $interlocution);
		$this->display('Index/answer_index');
	}
	
	public function search_answer() {
		$this ->meta_title = '合作问答';
		$keyword = I('post.keyword');
		$where = "question LIKE '%{$keyword}%' OR answer LIKE "."'%{$keyword}%'";
		$interlocution = M('interlocution')->where($where)->select();
		$this->assign('interlocution', $interlocution);
		$this->display('Index/answer_index');
	}
	
	public function contact() {
		$this ->meta_title = '联系我们';
		$this->display('Index/contact_index');
	}
	
	public function cooperation() {
		$this ->meta_title = '加盟案例';
		$this->display('Index/cooperation_index');
	}
	
	public function process() {
		$this ->meta_title = '合作加盟';
		$realname = I('post.realname');
		$phone = I('post.phone');
		if(!empty($realname) && !empty($phone)){
			$phone_rp = str_replace('-', '', $phone);
			$condition = "phone = {$phone_rp}";
			$check_parner = M('parner')->where($condition)->select();
			if (empty($check_parner)) {
				$parner = array('realname' => $realname, 'phone' => $phone_rp, 'time' => time());
				$result = M('parner')->data($parner)->add();
				if ($result > 1) {
					$this->ajaxReturn(array('status' => 1));
				} else {
					$this->error('数据插入错误');
				}
			} else {
				$this->ajaxReturn(array('status' => 2));
			}
		}
		$this->display('Index/process_index');
	}
	
	//最新资讯
	public function dynamic() {
		$this ->getArticles();
		$this ->meta_title = '最新资讯';
		$this->display('Index/dynamic_index');
	}
	
	public function product() {
		$this ->meta_title = '首页';
		$this->display('Index/product_index');
	}
	
	//文章详情页
	public function detail($id) {
		$article = D('Document') ->detail($id);
		$this ->assign('article', $article);
		$this ->assign('category', D('Category') ->info($article['category_id'],'title'));
		$this ->meta_title = $article['title'];
		$this ->display('Index/news_detail');
		
	}
	
	//文章列表
    public function lists($category) {
		$newField = 'id,title,cover_id';
		$listField = 'id,title,create_time';
		$this->assign('new', D('Document') ->lists($category,$order='create_time desc',$status=1,$newField=true,3));
		$this ->assign('lists', D('Document') ->lists($category,$order='create_time desc',$status=1,$listField,$limit='3,4'));
		$this ->meta_title = '更多资讯';
		$this ->display('Index/dynamic_list');
	}
	
	//获取新闻
	public function getArticles() {
		$companys = D('Category') ->info('companys','id');
		$industrys = D('Category') ->info('industrys','id');
		$newField = 'id,title,cover_id';
		$listField = 'id,title,create_time';
		$this ->assign('companys_category', $companys['id']);
		$this ->assign('industrys_category', $industrys['id']);
		$this->assign('newCompanys', D('Document') ->lists($companys['id'],$order='create_time desc',$status=1,$newField=true,3));
		$this ->assign('comanyList', D('Document') ->lists($companys['id'],$order='create_time desc',$status=1,$listField,$limit='3,4'));
		$this ->assign('newIndustrys', D('Document') ->lists($industrys['id'],$order='create_time desc',$status=1,$newField=true,3));
		$this ->assign('industrysList', D('Document') ->lists($industrys['id'],$order='create_time desc',$status=1,$listField,$limit='3,4'));
	}
}